package org.springagg.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springagg.consts.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LoginController {

    @RequestMapping("login")
    public String login(HttpServletRequest request,
                        @RequestParam("username") String username,
                        @RequestParam("password") String password,
                        @RequestParam("deviceid") String deviceid) {
        System.out.println("password: " + password +" deviceid:" + deviceid);
        HttpSession session = request.getSession();
        session.setAttribute(Constants.DEFAULT_SESSION_USERNAME, username);
        session.setAttribute("contextpath",request.getContextPath());
        //return "redirect:index";
        return "redirect:zhuanpan";
    }

    @RequestMapping("index")
    public String index(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("contextpath",request.getContextPath());
        return "index";
    }

    @RequestMapping("shake")
    //@ResponseBody
    public String shake (HttpServletRequest request){//,@RequestParam String speed
        return "shake";
    }

    @RequestMapping("zhuanpan")
    public String zhuanpan (HttpServletRequest request){//,@RequestParam String speed
        HttpSession session = request.getSession();
        session.setAttribute("contextpath",request.getContextPath());
        return "zhuanpan";
    }

    @RequestMapping("rock")
    public String rockhand(){
        return  "rock";
    }
}
